package sz.com.postoffice.jxyzwgcase.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sz.com.postoffice.jxyzwgcase.dao.node.ConstantDao;
import sz.com.postoffice.jxyzwgcase.pojo.ConstantDb;
import sz.com.postoffice.jxyzwgcase.service.ConstantDbService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 常量获取接口实现
 *
 * @author ycwu
 * @date 2020-12-16 09:26
 */
@Service
public class ConstantDbServiceImpl implements ConstantDbService {

    @Autowired
    private ConstantDao constantDao;

    //常量保存集合
    public static List<ConstantDb> constantDbs = new ArrayList<>();


    @Override
    public List<ConstantDb> getConstantDbs() {
        if (constantDbs.size() < 1) {
            constantDbs = constantDao.initConstant();
        }
        return constantDbs;
    }

    @Override
    public void freshConstantDbs() {
        constantDbs = constantDao.initConstant();
    }

    @Override
    public Map<String, String> findByModel(String model) {
        List<ConstantDb> constantDbList = constantDao.findByModel(model);
        Map<String, String> resultMap = new HashMap<>();
        for (ConstantDb constantDb : constantDbList) {
            resultMap.put(constantDb.getType(), constantDb.getField());
        }
        return resultMap;
    }
}
